//
//  NetWorkManager.m
//  VTravel
//
//  Created by lanouhn on 16/8/1.
//  Copyright © 2016年 xiaoYu. All rights reserved.
//

#import "NetWorkManager.h"
#import <AFNetworking/AFNetworking.h>

@implementation NetWorkManager


+ (void)requestForGETWithURL:(NSString *)url
                   paramater:(NSDictionary *)dic
                     success:(void(^)(id responseObject))success
                        fail:(void(^)(NSError *error))conError{
    // 创建一个网络请求管理对象
    AFHTTPSessionManager *manager = [AFHTTPSessionManager manager];
    
    // 设置返回数据
    manager.responseSerializer.acceptableContentTypes = [NSSet setWithObjects:@"text/html", @"application/json", @"text/jsvascript", nil];
    
    // 开始网络请求
    [manager GET:url parameters:dic progress:^(NSProgress * _Nonnull downloadProgress) {
        
    } success:^(NSURLSessionDataTask * _Nonnull task, id  _Nullable responseObject) {
        // 将请求成功返回的数据进行回调
        success(responseObject);
        
    } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
        // 将请求失败返回的数据进行回调
        conError(error);
    }];
    
}

+ (void)requestForPOSTWithURL:(NSString *)url
                    paramater:(NSDictionary *)dic
                      success:(void (^)(id))success
                         fail:(void (^)(NSError *))conError{
    
    // 创建网络请求管理对象
    AFHTTPSessionManager *manager = [AFHTTPSessionManager manager];
    
    // 设置返回数据
    manager.responseSerializer.acceptableContentTypes = [NSSet setWithObjects:@"text/html", @"application/json", @"text/jsvascript", nil];
    
    // 开始网络强求
    [manager POST:url parameters:dic progress:^(NSProgress * _Nonnull uploadProgress) {
        
    } success:^(NSURLSessionDataTask * _Nonnull task, id  _Nullable responseObject) {
        // 将请求成功返回的数据进行回调
        success(responseObject);
    } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
        // 将请求失败返回的数据进行回调
        conError(error);
    }];
    
    
}

@end
